# -*- coding: utf-8 -*-
# @File     : get_image_attr.py
# @Author   : bingjia
# @Time     : 2020/9/22 18:52
# @Desc     : 获取图片的属性信息

import exifread


def get_image_attr(image):
    """
    获取图片的属性信息
    :param image:
    :return:
    """
    with open(image, 'rb') as f:
        tags = exifread.process_file(f)

        time = tags['EXIF DateTimeOriginal'].printable

        if "GPS GPSLatitudeRef" not in tags or "GPS GPSLongitudeRef" not in tags:
            return time, None, None

        lat = tags["GPS GPSLatitude"].printable[1:-1].replace(" ", "").replace("/", ",").split(",")
        lat = float(lat[0]) + float(lat[1]) / 60 + float(lat[2]) / float(lat[3]) / 3600

        lng = tags["GPS GPSLongitude"].printable[1:-1].replace(" ", "").replace("/", ",").split(",")
        lng = float(lng[0]) + float(lng[1]) / 60 + float(lng[2]) / float(lng[3]) / 3600

        return time, lat, lng


# print(get_image_attr(r'D:\AppStore\PycharmStore\operational_platform\Detection\network\yolov5\data\images\000001.jpg'))
